/***************************************************************************
 *   Copyright (C) 2008, 2010 by Lasse Liehu                               *
 *   lliehu@kolumbus.fi                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef GOOGLELOGINDATA_H
#define GOOGLELOGINDATA_H

#include <QObject>

// forward declarations
class QString;
class GoogleLoginDataPrivate;

/**
 * This class is used as a storage class for information regarding Google
 * account password and email, and current SID (session id). You don't need to
 * worry about details such as what kind of effect the settings of one login
 * setting has on other login settings or anything about storing a non-saved
 * password.
 *
 * You have to, however, take care of saving and loading of these settings
 * to/from your own settings storage (some registry keys, file somewehere etc).
 *
 * You also have to connect a password asker. You can just use the default asker
 * by calling connectDefaultPasswordAsker(), but you can also connect your own
 * asker by connecting your asker slot to signal
 * GoogleLoginData::passwordWanted().
 *
 * After signal passwordWanted() has been emitted the object waits for someone
 * to call setPassword(const QString&). Only after that does it continue its
 * things.
 *
 * @attention When using this class be sure to set the application name using
 *     QCoreApplication::applicationName() before using this class.
 *
 * @note This class is thread-safe.
 */
class GoogleLoginData : public QObject
{
    Q_OBJECT

    public:
        enum PasswordType { Normal, Cached, Saved };

        explicit GoogleLoginData();
        ~GoogleLoginData();

        QString password(PasswordType type = Normal);
        QString email() const;
        QString sid() const;
        bool isPasswordSaved() const;
        bool isAlwaysAskPasswordOn() const;

        void connectDefaultPasswordAsker();
        void disconnectCurrentPasswordAsker();
    signals:
        void passwordChanged(const QString& );
        void emailChanged(const QString& );
        void sidChanged(const QString& );
        void isPasswordSavedStatusChanged(bool newStatus);
        void passwordWanted();
    public slots:
        void setPassword(const QString& passwd);
        void setEmail(const QString& email);
        void setSid(const QString& sid);
        void setSavePassword(bool val);
        void setAlwaysAskPassword(bool val);
    private slots:
        void askPasswordFromUser();
    private:
        class SleeperThread;

        GoogleLoginDataPrivate *const d;
};

#endif
